package com.medical.project.system.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.framework.aspectj.lang.annotation.Log;
import com.medical.framework.aspectj.lang.enums.BusinessType;
import com.medical.project.system.domain.FamilyArchives;
import com.medical.project.system.service.IFamilyArchivesService;
import com.medical.framework.web.controller.BaseController;
import com.medical.framework.web.domain.AjaxResult;
import com.medical.common.utils.poi.ExcelUtil;
import com.medical.framework.web.page.TableDataInfo;

/**
 * 家庭档案信息Controller
 *
 * @author tale
 * @date 2020-06-20
 */
@RestController
@RequestMapping("/system/archives")
public class FamilyArchivesController extends BaseController {
    @Autowired
    private IFamilyArchivesService familyArchivesService;

    /**
     * 查询家庭档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archives:list')")
    @GetMapping("/list")
    public TableDataInfo list(FamilyArchives familyArchives) {
        startPage();
        List<FamilyArchives> list = familyArchivesService.selectFamilyArchivesList(familyArchives);
        return getDataTable(list);
    }

    /**
     * 导出家庭档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:archives:export')")
    @Log(title = "家庭档案信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FamilyArchives familyArchives) {
        List<FamilyArchives> list = familyArchivesService.selectFamilyArchivesList(familyArchives);
        ExcelUtil<FamilyArchives> util = new ExcelUtil<FamilyArchives>(FamilyArchives.class);
        return util.exportExcel(list, "archives");
    }

    /**
     * 获取家庭档案信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:query')")
    @GetMapping(value = "/{familyCode}")
    public AjaxResult getInfo(@PathVariable("familyCode") String familyCode) {
        return AjaxResult.success(familyArchivesService.selectFamilyArchivesById(familyCode));
    }

    /**
     * 新增家庭档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:add')")
    @Log(title = "家庭档案信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyArchives familyArchives) {


        return toAjax(familyArchivesService.insertFamilyArchives(familyArchives));
    }

    /**
     * 修改家庭档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:edit')")
    @Log(title = "家庭档案信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyArchives familyArchives) {
        return toAjax(familyArchivesService.updateFamilyArchives(familyArchives));
    }

    /**
     * 删除家庭档案信息
     */
    @PreAuthorize("@ss.hasPermi('system:archives:remove')")
    @Log(title = "家庭档案信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{familyCodes}")
    public AjaxResult remove(@PathVariable String[] familyCodes) {
        return toAjax(familyArchivesService.deleteFamilyArchivesByIds(familyCodes));
    }
}
